import logging
import logging.config

import yaml

from utils.nlp_client import NLPService

NLP_SERVICE = 'nlp_service'
USER_DICT = 'user_dict'
MODEL_PATH = 'model_path'
KEYWORD_METHOD = 'keyword_method'
APP_SERVE = 'app_serve'


ARG_TEXT = 'text'
ARG_TOP_K = 'keyword_top_k'
ARG_TOP_N = 'keyword_cloud_n'
ARG_ALLOW_POS = 'keyword_allow_pos'
ARG_TF = 'keyword_tf'


def load_yaml(yaml_file):
    with open(yaml_file, 'r') as infile:
        config = yaml.load(infile)
    return config


def set_logging(conf_file):
    config = load_yaml(conf_file)
    logging.config.dictConfig(config)

config_file = '/home/alpha/youka/youka-search-api/config/config.yml'
logging_config_file = '/home/alpha/youka/youka-search-api/config/logging.yml'

set_logging(logging_config_file)

config = load_yaml(config_file)


logger = logging.getLogger()

nlp_conf = config['nlp_client']
defaults = {}
if 'keyword_top_k' in nlp_conf:
    defaults['keyword_top_k'] = nlp_conf['keyword_top_k']
if 'keyword_allow_pos' in nlp_conf:
    defaults['keyword_allow_pos'] = nlp_conf['keyword_allow_pos']
if 'keyword_cloud_n' in nlp_conf:
    defaults['keyword_cloud_n'] = nlp_conf['keyword_cloud_n']
nlp_service = NLPService(nlp_conf['host'], nlp_conf['port'], nlp_conf['timeout'], defaults=defaults)

print(nlp_service.keywords("女装 大码", 10, []))
print(nlp_service.wordcloud('纤莉秀', 100, (), 1000))